import axios from '@/libs/axios1'
let jsonHeaders = { 'content-type': 'application/json;charset=UTF-8' }

/**
 * 根据条件查询计费金额
 * @param {*} param0 
 * @returns 
 */
export const getPrice = ({ resourceType = 'instance', maxBandwidth, period, priceUnit }) => {
    return axios({
        url: `/public-cloud-adapter/price/default`,
        method: 'get',
        params: {
            resourceType,
            maxBandwidth,
            period,
            priceUnit
        },
        headers: jsonHeaders
    })
}

/**
 * 查询阿里云实例
 * @param {*} param0 
 */
export const getInstanceList = ({ instanceName, pageSize, pageIndex, projectId, id }) => {
    return axios({
        url: `/public-cloud-adapter/instances`,
        method: 'get',
        params: {
            name: instanceName,
            pageSize,
            pageIndex,
            projectId,
            id
        },
        headers: jsonHeaders
    })
}

/**
 * 查询外网IP的分配记录
 * @param {*} param0 
 * @returns 
 */
export const getOperatingRecordList = ({ pageIndex = 1, pageSize = 10, teamId, sceneId }) => {
    return axios({
        url: `/compete/publicIpRecord/page`,
        method: 'get',
        params: {
            pageIndex,
            pageSize,
            teamId,
            sceneId
        },
        headers: jsonHeaders
    })
}

/**
 * 为场景内的团队分配外网IP
 * @param {*} sceneId 指定场景
 * @param {*} projectId 指定工程
 * @param {*} data 需绑定的团队的信息列表
 */
export const assigningPublicIP = (sceneId, projectId, data) => {
    return axios({
        url: `/compete/publicIpRecord/${sceneId}/${projectId}`,
        method: 'post',
        data,
        headers: jsonHeaders
    })
}

/**
 * 解绑所有已分配的团队外网IP
 * @param {*} projectId 指定工程ID
 * @returns 
 */
export const allUnbundlePublicIP = projectId => {
    return axios({
        url: `/compete/publicIpRecord/${projectId}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

/**
 * 批量解绑外网IP
 * @param {*} ids 
 */
export const batchUnbundlePublicIP = ids => {
    return axios({
        url: `/compete/publicIpRecord/batch`,
        method: 'post',
        data: ids,
        headers: jsonHeaders
    })
}

/**
 * 单个解绑指定的外网IP
 * @param {*} id 
 * @returns 
 */
export const unbundlePublicIP = id => {
    return axios({
        url: `/compete/publicIpRecord/One/${id}`,
        method: 'delete',
        headers: jsonHeaders
    })
}

/**
 * 重置团队的外网IP
 * @param {*} instanceId 指定实例ID
 * @returns 
 */
export const resetPublicIp = (instanceId) => {
    return axios({
        url: `/compete/publicIpRecord/${instanceId}`,
        method: 'put',
        headers: jsonHeaders
    })
}

/**
 * 修改工程下所有外网IP的带宽
 * @param {*} projectId 工程ID
 * @param {*} maxBandwidth 最大带宽 
 * @returns 
 */
export const updateBandwidth = (projectId, maxBandwidth) => {
    return axios({
        url: `/public-cloud-adapter/instances/eip/maxBandwidth/project`,
        method: 'put',
        params: {
            projectId,
            maxBandwidth
        },
        headers: jsonHeaders
    })
}

/**
 * 获取外网IP操作日志
 * @param {*} param0 
 * @returns 
 */
export const getLogs = ({ pageIndex, pageSize, projectId, teamId, apiName }) => {
    return axios({
        url: `/openrange-log/log/logs/tag`,
        method: 'post',
        data: {
            projectId, 
            teamId,
            apiName
        },
        params: {
            pageIndex,
            pageSize
        },
        headers: jsonHeaders
    })
}

/**
 * 获取vnc地址
 * @param {*} id 
 * @param {*} params 
 * @returns 
 */
export const getVNC= (id, params) => {
    return axios({
        url: `/public-cloud-adapter/instances/${id}/vnc`,
        method: 'get',
        params:params,
        headers: jsonHeaders
    })
}

/**
 * 移除公网地址
 * @param {*} id 
 * @returns 
 */
export const removeAddress = id => {
    return axios({
        url: `/public-cloud-adapter/instances/${id}/eip`,
        method: 'delete',
        headers: jsonHeaders
    })
}

/**
 * 云服务器的开、关、重启
 * @param {*} id 
 * @param {*} params 
 * @returns 
 */
export const oppublicServer = (id, params) => {
    return axios({
        url: `/public-cloud-adapter/instances/${id}/actions/${params}`,
        method: 'post',
        headers: jsonHeaders
    })
}

/**
 * 查询安全组
 * @param {*} id 
 * @param {*} params 
 * @returns 
 */
export const getSecurityGroups = (id, params)=> {
    return axios({
      url: `public-cloud-adapter/securityGroups/${id}/rules`,
      method: 'get',
      params: params,
      headers: jsonHeaders
    })
}